package cn.tedu.basic;

import java.io.*;
import java.lang.reflect.Method;
import java.util.Scanner;

//测试文件复制--copyFile(x,y);
public class Test1_Copy{
    public static void main(String[] args) throws Exception {
        System.out.println("请输入源文件的路径:");
        String m=new Scanner(System.in).nextLine();
        System.out.println("请输入目标文件的路径:");
        String n=new Scanner(System.in).nextLine();
        copyFile(m,n);
        System.out.println("文件复制已经完成");
        Method();


    }
    public static void copyFile(String m,String n) throws IOException {
        InputStream In =new BufferedInputStream(new FileInputStream(m));
        OutputStream Ins =new BufferedOutputStream(new FileOutputStream(n));
        int b =0;
        while ((b=In.read())!=-1){
            Ins.write(b);
        }
        In.close();
        Ins.close();//刷新并关闭
//      Ins.flush();//刷新
    }
    //
    public static void Method() throws Exception {
        System.out.println("请输入原文件路径：");
        String x =new Scanner(System.in).nextLine();
        System.out.println("请输入目标文件路径：");
        String y =new Scanner(System.in).nextLine();
        copyFile1(x,y);
        System.out.println("文件复制完成");
    }
    public static void copyFile1(String x,String y) throws Exception {
        InputStream inp =new BufferedInputStream(new FileInputStream(x));
        OutputStream out =new BufferedOutputStream(new FileOutputStream(y));
        int z =0;
        while ((z=inp.read())!=-1){
            out.write(z);
        }
        inp.close();
        out.close();
        out.flush();
    }





}
